﻿using Common;
using Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Login_DAL : IDAL.ilogin_IDAL
    {
        //login_Com manages = new Account_Manage_MD();
        string IDAL.ilogin_IDAL.isLogin(string Accout, string pwd,string query)
        {
            string s = "";
            switch (query)
            {
                case "管理员":s= "Administrator_Account"; break;
                case "老师": s = "Teacher_Account"; break;
            }
            SqlDataReader dataReader=null;
            if (query=="学生")
            {
                dataReader = DAL.SQLHepler.GetDataReader($"select StudentId as Account,password,StudentName as UserName from Examinee_info where StudentId='{Accout}' and status=0");
            }
            else
            {
                 dataReader = DAL.SQLHepler.GetDataReader($"select Account,password,UserName  from {s} where Account='{Accout}' and status=0");
            }
            
            if ( dataReader != null )
            {
                if (dataReader.Read())
                {
                    login_Com.account.Account = dataReader["Account"].ToString();
                   login_Com.account.password = dataReader["password"].ToString();
                   login_Com.account.UserName = dataReader["UserName"].ToString();
                   
                }
               
                dataReader.Close();
            }
            else
            {
                return null;
            }
            if (pwd != login_Com.account.password)
            {
                return null;
            }
            return login_Com.account.UserName;
        }
    }
}
